package com.ITXu.reggie.config;

import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.util.pattern.PathPattern;

import com.ITXu.reggie.commom.JacksonObjectMapper;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class webMvcConfig extends WebMvcConfigurationSupport{
	
	//静态资源映射
	@Override
	protected void addResourceHandlers(ResourceHandlerRegistry registry) {
		System.out.println("静态资源映射开始...");
		registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
		registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
	
	}
	
	//扩展springmvc框架的消息转换器	
	@Override
	protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
		//创建一个消息转换器
		MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
		//在消息转换器中的objectMapper更新为JacksonObjectMapper
		jackson2HttpMessageConverter.setObjectMapper(new JacksonObjectMapper());
		//将这个消息转换器加入到springmvc框架的消息转换器集合中
		converters.add(0, jackson2HttpMessageConverter);
		super.extendMessageConverters(converters);
	}
}
